package project.layer.ant;


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import project.layer.agents.ReportReceiver;
import project.layer.agents.TruckAgent;
import project.layer.physical.Crossroad;
import project.layer.physical.Path;
import project.layer.physical.Road;

public abstract class ExplorationAnt extends HoppingAnt {
	
	private int nbOfPnDSequencesLeft;

	protected Path followedPath;
	protected Path pathOfPreviousPnDSequences = new Path();
	private ReportReceiver receiver;
	private ReportReceiver earlierReceiver;


	/**
	 * Constructor of an ExplorationAnt used upon creation of the first ExplorationAnt 
	 */
	public ExplorationAnt(TruckAgent sendingAgent, Crossroad location, int maxHops, int nbOfPnDSequencesLeft){
		super(sendingAgent,location,maxHops);
		this.receiver = sendingAgent;
		this.earlierReceiver = sendingAgent;
		this.nbOfPnDSequencesLeft = nbOfPnDSequencesLeft;
		this.followedPath = new Path();
	}
	
	/**
	 * Constructor of an ExplorationAnt used upon creation of new ants from the previous ant. 
	 */
	ExplorationAnt(TruckAgent sendingAgent, ReportReceiver receiver, ReportReceiver earlierRec, Crossroad location, int maxHops, int currentHopCount, Path currentPath,int nbOfPnDSequencesLeft, Road lastRoad,long travelledDistance, Path previousPath){
		super(sendingAgent, location, maxHops, currentHopCount, lastRoad, travelledDistance);
		this.nbOfPnDSequencesLeft = nbOfPnDSequencesLeft;
		this.followedPath = currentPath.getClone();
		this.receiver =  receiver;
		if(earlierRec == null){
			this.earlierReceiver = sendingAgent;
		}
		else{
			this.earlierReceiver = earlierRec;
		}
		if(previousPath != null){
			this.pathOfPreviousPnDSequences = previousPath.getClone();
		}
		
	}
	
	/**
	 * Constructor of an ExplorationAnt used upon creation of a new ExplorationAnt at the dropofflocation of a previous PND sequence
	 */
	ExplorationAnt(TruckAgent sendingAgent, ReportReceiver receiver, ReportReceiver earlierRec, Crossroad location, int maxHops, Path previousPath ,int nbOfPnDSequencesLeft){
		super(sendingAgent, location, maxHops, 0, null, 0);
		this.nbOfPnDSequencesLeft = nbOfPnDSequencesLeft;
		this.followedPath = new Path();
		this.receiver = receiver;
		if(earlierRec == null){
			this.earlierReceiver = sendingAgent;
		}
		else{
			this.earlierReceiver = earlierRec;
		}
		this.pathOfPreviousPnDSequences = previousPath.getClone();
	}
	
	
	public boolean hasPreviousPath(){
		return pathOfPreviousPnDSequences != null;
	}
	
	
	@Override
	public void cloneAndSpread() {
		// TODO Auto-generated method stub

	}

	@Override
	public TruckAgent getSendingAgent() {
		return (TruckAgent)this.sendingAgent;
	}
	

	
	public Path getPath(){
		return followedPath.getClone();
	}
	
	public int getNbOfPnDSequencesLeft() {
		return nbOfPnDSequencesLeft;
	}
	
	public void decreaseNbOfPnDSequencesLeft(){
		nbOfPnDSequencesLeft--;
	}

	public Path getPathOfPreviousPnDSequences() {
		return pathOfPreviousPnDSequences;
	}
	
	public List<Integer> getDestinationsOfPreviousPnDSequences(){
		if(hasPreviousPath()){
			return getPathOfPreviousPnDSequences().getDestinations();
		}
		else{
			return new LinkedList<Integer>();
		}
	}

	public ReportReceiver getReceiver() {
		return receiver;
	}

	public ReportReceiver getEarlierReceiver() {
		return earlierReceiver;
	}


}
